//question_detail_more_answer
//加载更多回答
exports.question_detail_more_answer = function (req, res) {
//问题内容页
    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;
    //最终结果
    var resultData = {};

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip * limit;
    //任务流创建
    async.waterfall([
        //获取回答
        function (cb) {

            var u_id = restfulParams.u_id;

            if (u_id) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_answer_userinfo + "/fcc_fcid/" + restfulParams.fc_id + "/skip/" + skip + "/limit/" + limit + "/fca_uid/" + u_id,
                        method: 'POST',
                        data: {
                            fields: [
                                "fca_id",
                                "fca_uid",
                                "fca_content",
                                "fca_images",
                                "fca_zan_count",
                                "fca_comment_count",
                                "fca_create_time",
                                "u_nickname",
                                "u_type",
                                "u_id",
                                "u_oid",
                                "u_header_url"
                            ].join(",")
                        }

                    },
                    function (err, data) {
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        resultData.answerData = data.data;

                        cb();
                    }
                );
            } else {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_answer_userinfo + "/fcc_fcid/" + restfulParams.fc_id + "/skip/" + skip + "/limit/" + limit,
                        method: 'POST',
                        data: {
                            fields: [
                                "fca_id",
                                "fca_uid",
                                "fca_content",
                                "fca_images",
                                "fca_zan_count",
                                "fca_comment_count",
                                "fca_create_time",
                                "u_nickname",
                                "u_type",
                                "u_id",
                                "u_oid",
                                "u_header_url"
                            ].join(",")
                        }

                    },
                    function (err, data) {
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        resultData.answerData = data.data;

                        cb();
                    }
                );
            }
        },
        function (cb) {

            var answerData = resultData.answerData;

            var tasks = [];

            answerData.forEach(function (item, i) {

                console.log(item.u_id);
                tasks.push(function (cb) {


                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.searchOrganization + "/o_uid/" + item.u_id,
                            method: 'POST',
                            data: {
                                fields: ["o_name", "o_logo"].join(",")
                            }
                        },
                        function (err, data) {

                            console.log(data.data);
                            if(data.data.length>0){
                                item.isOganization = 1;

                                item.o_name = data.data[0].o_name;

                                item.o_logo = data.data[0].o_logo;

                                cb();
                            }else{
                                item.isOganization = 0;

                                cb();
                            }

                        }
                    );

                })
            });
            async.waterfall(tasks, cb);
        },
    ], function (err, result) {

        //返回最终拼接结果
        RES.response(res, true, resultData);

    });

}